package com.sl.au.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sl.au.entity.EXDEgetPayDetailHistoryWithContract;
import com.sl.au.repository.EXDEgetPayDetailHistoryWithContractRepositor;
import com.sl.au.service.EXDEgetPayDetailHistoryWithContractService;

@Service("EXDEgetPayDetailHistoryWithContractService")
@Transactional
public class EXDEgetPayDetailHistoryWithContractServiceImpl extends BaseServiceImpl implements EXDEgetPayDetailHistoryWithContractService{
	@Autowired
	EXDEgetPayDetailHistoryWithContractRepositor exdegetPayDetailHistoryWithContractService;
	
	@Override
	public EXDEgetPayDetailHistoryWithContractRepositor getRepository() {
		// TODO A1uto-generated method stub
		return this.exdegetPayDetailHistoryWithContractService;
	}

	@Override
	public List<EXDEgetPayDetailHistoryWithContract> getMyPage(int start, int length, Map<String, String> condition) {
		// TODO Auto-generated method stub
		Page<EXDEgetPayDetailHistoryWithContract> pages=null; 
		Pageable pageable=new PageRequest(start/length,length,Sort.Direction.DESC,"dPaidDate");
		if(condition.get("key") != null && !condition.get("key").toString().equals("")){
			pages = exdegetPayDetailHistoryWithContractService.findAllTrance(condition.get("superior"),condition.get("sContractType"),condition.get("key"),pageable);
		}else{
			pages = exdegetPayDetailHistoryWithContractService.findAllTrance(condition.get("superior"),condition.get("sContractType"),pageable);
		}
//		pages = exdegetPayDetailHistoryWithContractService.findAllTrance(condition.get("superior"),condition.get("sContractType"),pageable);
		return pages.getContent();
	}

	@Override
	public long getMyPageCount(int start, int length, Map<String, String> condition) {
		// TODO Auto-generated method stub
		long count = 0;
		if(condition.get("key") != null && !condition.get("key").equals("")){
			count = exdegetPayDetailHistoryWithContractService.findAllTrancegetCount(condition.get("superior"),condition.get("sContractType"),condition.get("key"));
		}else{
			count = exdegetPayDetailHistoryWithContractService.findAllTrancegetCount(condition.get("superior"),condition.get("sContractType"));
		}
		return count;
	}

}
